//
//  MessageCel.m
//  BiuTalk
//
//  Created by 楼楚 on 16/3/29.
//  Copyright © 2016年 Chu Lou. All rights reserved.
//

#import "MessageCell.h"

@implementation MessageCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self buildCell];
    }
    return self;
}
- (void)buildCell{
    
    UIImage *leftImage = [UIImage imageNamed:@"ReceiverTextNodeBkg.png"];
    UIImage *rightImage = [UIImage imageNamed:@"SenderTextNodeBkg.png"];
//    生成新image
    leftImage = [leftImage stretchableImageWithLeftCapWidth:30 topCapHeight:35];
    rightImage = [rightImage stretchableImageWithLeftCapWidth:30 topCapHeight:35];
    
//    别人的头像
    self.leftHeadImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 30, 30)];
    self.leftHeadImage.layer.masksToBounds = YES;
    self.leftHeadImage.layer.cornerRadius = 12;
    self.leftHeadImage.image = [UIImage imageNamed:@"you.png"];
    [self.contentView addSubview:self.leftHeadImage];

//别人的语音气泡
    self.leftVideoButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.leftVideoButton.frame = CGRectMake(40, 5, 200, 35);
   
    [self.contentView addSubview:self.leftVideoButton];
    
    self.leftPicImage = [[UIImageView alloc] initWithFrame:CGRectMake(40, 5, 100, 100)];
    self.leftPicImage.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:self.leftPicImage];
    
    self.lefeView = [[UIImageView alloc] initWithFrame:CGRectMake(40, 5, 105, 105)];
    self.lefeView.image = leftImage;
    // 这里不是一个小像素的图片？？
    [self.contentView addSubview:self.lefeView];
    
    
    
    self.leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 1, 1)];
    self.leftLabel.font = [UIFont systemFontOfSize:14];
    
    self.leftLabel.numberOfLines = 0; // 换行
    
    self.leftLabel.backgroundColor = [UIColor clearColor];// 设置透明的
    
    [self.lefeView addSubview:self.leftLabel];

//    自己的头像
//    self.rightHeadImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width - 35 , 5, 30, 30)];
    self.rightHeadImage = [[UIImageView alloc]init];
    
    NSLog(@"---------%f",self.frame.size.width);
    self.rightHeadImage.backgroundColor = [[UIColor redColor]colorWithAlphaComponent:0.3f];
    self.rightHeadImage.layer.masksToBounds = YES;
    self.rightHeadImage.layer.cornerRadius = 12;
    self.rightHeadImage.image = [UIImage imageNamed:@"me.png"];
    [self.contentView addSubview:self.rightHeadImage];
    
    self.rightVideoButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.rightVideoButton.frame = CGRectMake(self.frame.size.width - 45 - 40, 5, 200, 35);
   
    [self.contentView addSubview:self.rightVideoButton];
    
    self.rightPicImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width - 45 - 30, 5, 100, 100)];
    self.rightPicImage.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:self.rightPicImage];

    
//    接收的图片view
    
    self.rightView = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width - (66+40), 5, 105, 105)];
    self.rightView.image = rightImage;
    [self.contentView addSubview:self.rightView];
    
    
    self.rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 1, 1)];
    self.rightLabel.font = [UIFont systemFontOfSize:14];
    self.rightLabel.backgroundColor = [UIColor clearColor];
    self.rightLabel.numberOfLines = 0;
    [self.rightView addSubview:self.rightLabel];
    
    
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 5)];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"MM-dd hh:mm:ss"];
    self.timeLabel.text = [formatter stringFromDate:[NSDate date]];
    self.timeLabel.font = [UIFont systemFontOfSize:5.f];
    self.timeLabel.textColor = [UIColor blackColor];
    self.timeLabel.textAlignment = NSTextAlignmentCenter;
    
    [self.contentView addSubview:self.timeLabel];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


@end
